This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(plotly)
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.5.2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(readxl)
## Warning: package 'readxl' was built under R version 3.5.2
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(xtable)
Sys.setenv("plotly_username"="kassio.silva")
Sys.setenv("plotly_api_key"="0BULwdSIo8khglNH31kJ")
ingressantes2017nota_M <- read.csv("C:/Users/erica.santos/workspace/trabalho/THE_rankings/Impact Ranking/consulta_geral_discente (2).csv",
header = TRUE, sep=";", colClasses = c("character"))
ingressantes2017nota_F <- read.csv("C:/Users/erica.santos/workspace/trabalho/THE_rankings/Impact Ranking/consulta_geral_discente (3).csv",
header = TRUE, sep=";", colClasses = c("character"))
ingressantes2017nota_M <- filter(ingressantes2017nota_M, startsWith(ingressantes2017nota_M$matricula, '2017'))
ingressantes2017nota_F <- filter(ingressantes2017nota_F, startsWith(ingressantes2017nota_F$matricula, '2017'))
iris %>% group_by(Species) %>% summarise(avg = mean(Sepal.Length))
## # A tibble: 3 x 2
## Species avg
## <fct> <dbl>
## 1 setosa 5.01
## 2 versicolor 5.94
## 3 virginica 6.59
# Notas médias dos cursos masculino
nota_M = ingressantes2017nota_M %>% group_by(curso)
nota_M$ira <- as.numeric(nota_M$ira)
nota_M$iea <- as.numeric(nota_M$iea)
nota_M = nota_M %>% summarise(avg_M = mean(ira))
nota_M = nota_M[complete.cases(nota_M), ]
# Notas médias dos cursos feminino
nota_F = ingressantes2017nota_F %>% group_by(curso)
nota_F$ira <- as.numeric(nota_F$ira)
nota_F$iea <- as.numeric(nota_F$iea)
nota_F = nota_F %>% summarise(avg_F = mean(ira))
nota_F = nota_F[complete.cases(nota_F), ]
# Numero de homens por curso
n_M <- ingressantes2017nota_M %>% group_by(curso) %>% count()
M_nota_numero = inner_join(nota_M, n_M, by="curso")
# Numero de mulheres por curso
n_F <- ingressantes2017nota_F %>% group_by(curso) %>% count()
F_nota_numero = inner_join(nota_F, n_F, by="curso")
data = inner_join(F_nota_numero, M_nota_numero, by="curso")
data = data %>% mutate(diff = abs(data$avg_M-data$avg_F), indicador = ifelse(avg_F > avg_M, 1, 0))
# Plotando o gráfico
f <- list(
family = "Times New Roman",
size = 24,
color = "#7f7f7f"
)
x <- list(
title = "Masculino",
titlefont = f,
showgrid = FALSE
)
y <- list(
title = "Feminino",
titlefont = f,
showgrid = FALSE
)
#Use the ideal sizeref value
desired_maximum_marker_size <- 30
your_list_of_size_values <- data['diff']
sizeref <- 2.0 * max(your_list_of_size_values) / (desired_maximum_marker_size**2)
p <- plot_ly(data, x = ~n.y , y = ~n.x,
text = ~paste("Curso: ", curso, "Diferença: ", round(diff, 3)), type = 'scatter', mode = 'markers',
marker = list(size = ~2*diff, opacity = 0.5, color = ~indicador, sizemode = 'area', sizeref = sizeref)) %>%
layout(title = 'Diferença de notas entre homens e mulheres por curso',
xaxis = x,
yaxis = y)
p
#chart_link = api_create(p, filename="diff_notas")
#chart_link
# Testes de hipóteses para diferença de médias:
# Teste t
cursos_para_teste_t = data[data$n.x >= 25 & data$n.y >= 25, ]$curso
p_valores_t = c(0,0,0,0,0)
for(i in cursos_para_teste_t){
curso_M = filter(ingressantes2017nota_M, curso == i)
curso_F = filter(ingressantes2017nota_F, curso == i)
rr = t.test(as.numeric(curso_M$ira),as.numeric(curso_F$ira))
p_valores_t = rbind(p_valores_t, c(as.numeric(curso_M$ira) %>% mean,
nrow(curso_M),
as.numeric(curso_F$ira) %>% mean,
nrow(curso_F),
rr$p.value))
}
p_valores_t = p_valores_t[-1, ]
rownames(p_valores_t) = cursos_para_teste_t
colnames(p_valores_t) = c("Média Homens", "N Homens", "Média Mulheres", "N Mulheres", "Valor p")
p_valores_t
## Média Homens N Homens
## ADMINISTRAÇÃO 26.27854 58
## AGRONOMIA 40.77209 77
## ARQUITETURA E URBANISMO 64.85362 32
## ENGENHARIA CIVIL 70.66106 140
## INTERDISCIPLINAR EM CIÊNCIA E TECNOLOGIA 37.54158 578
## Média Mulheres N Mulheres
## ADMINISTRAÇÃO 41.69677 30
## AGRONOMIA 36.61436 25
## ARQUITETURA E URBANISMO 62.91340 27
## ENGENHARIA CIVIL 71.54096 48
## INTERDISCIPLINAR EM CIÊNCIA E TECNOLOGIA 47.18982 98
## Valor p
## ADMINISTRAÇÃO 0.028713152
## AGRONOMIA 0.564468515
## ARQUITETURA E URBANISMO 0.796912522
## ENGENHARIA CIVIL 0.826264346
## INTERDISCIPLINAR EM CIÊNCIA E TECNOLOGIA 0.004931084
# Teste de Mann-Whitney
cursos_para_teste_mw = data[(data$n.x <= 25 & data$n.x >= 8) & (data$n.y <= 25 & data$n.y >= 8), ]$curso
p_valores_mw = c(0,0,0)
for(i in cursos_para_teste_mw){
curso_M = filter(ingressantes2017nota_M, curso == i)
curso_F = filter(ingressantes2017nota_F, curso == i)
rr = wilcox.test(as.numeric(curso_M$ira),as.numeric(curso_F$ira))
p_valores_mw = rbind(p_valores_mw, c(as.numeric(curso_M$ira) %>% mean,
nrow(curso_M),
as.numeric(curso_F$ira) %>% mean,
nrow(curso_F),
rr$p.value))
}
## Warning in rbind(p_valores_mw, c(as.numeric(curso_M$ira) %>% mean,
## nrow(curso_M), : number of columns of result is not a multiple of vector
## length (arg 1)
## Warning in wilcox.test.default(as.numeric(curso_M$ira),
## as.numeric(curso_F$ira)): cannot compute exact p-value with ties
## Warning in wilcox.test.default(as.numeric(curso_M$ira),
## as.numeric(curso_F$ira)): cannot compute exact p-value with ties
## Warning in wilcox.test.default(as.numeric(curso_M$ira),
## as.numeric(curso_F$ira)): cannot compute exact p-value with ties
## Warning in wilcox.test.default(as.numeric(curso_M$ira),
## as.numeric(curso_F$ira)): cannot compute exact p-value with ties
## Warning in wilcox.test.default(as.numeric(curso_M$ira),
## as.numeric(curso_F$ira)): cannot compute exact p-value with ties
p_valores_mw = p_valores_mw[-1, ]
rownames(p_valores_mw) = cursos_para_teste_mw
colnames(p_valores_mw) = c("Média Homens", "N Homens", "Média Mulheres", "N Mulheres", "Valor p")
p_valores_mw
## Média Homens N Homens Média Mulheres N Mulheres
## COMPUTAÇÃO E INFORMÁTICA 39.95010 20 45.72617 12
## ECOLOGIA 29.81012 22 24.89240 12
## LETRAS / LIBRAS 56.14655 11 52.27267 21
## MEDICINA 60.50248 25 66.90201 15
## MEDICINA VETERINÁRIA 54.85037 24 54.59835 23
## ZOOTECNIA 27.59518 24 41.20950 16
## Valor p
## COMPUTAÇÃO E INFORMÁTICA 0.86306626
## ECOLOGIA 0.82772050
## LETRAS / LIBRAS 0.79584738
## MEDICINA 0.43364075
## MEDICINA VETERINÁRIA 1.00000000
## ZOOTECNIA 0.06631793
# Tabelas para o Rmarkdown
knitr::kable(p_valores_t, "markdown")
| Média Homens | N Homens | Média Mulheres | N Mulheres | Valor p | |
|---|---|---|---|---|---|
| ADMINISTRAÇÃO | 26.27854 | 58 | 41.69677 | 30 | 0.0287132 |
| AGRONOMIA | 40.77209 | 77 | 36.61436 | 25 | 0.5644685 |
| ARQUITETURA E URBANISMO | 64.85362 | 32 | 62.91340 | 27 | 0.7969125 |
| ENGENHARIA CIVIL | 70.66106 | 140 | 71.54096 | 48 | 0.8262643 |
| INTERDISCIPLINAR EM CIÊNCIA E TECNOLOGIA | 37.54158 | 578 | 47.18982 | 98 | 0.0049311 |
knitr::kable(p_valores_mw, "markdown")
| Média Homens | N Homens | Média Mulheres | N Mulheres | Valor p | |
|---|---|---|---|---|---|
| COMPUTAÇÃO E INFORMÁTICA | 39.95010 | 20 | 45.72617 | 12 | 0.8630663 |
| ECOLOGIA | 29.81012 | 22 | 24.89240 | 12 | 0.8277205 |
| LETRAS / LIBRAS | 56.14655 | 11 | 52.27267 | 21 | 0.7958474 |
| MEDICINA | 60.50248 | 25 | 66.90201 | 15 | 0.4336408 |
| MEDICINA VETERINÁRIA | 54.85037 | 24 | 54.59835 | 23 | 1.0000000 |
| ZOOTECNIA | 27.59518 | 24 | 41.20950 | 16 | 0.0663179 |